package com.javaclimb.music.service.Impl;

import com.javaclimb.music.dao.SingerMapper;
import com.javaclimb.music.domain.Singer;
import com.javaclimb.music.enums.ResponseEnum;
import com.javaclimb.music.service.SingerService;
import com.javaclimb.music.vo.ResponseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.javaclimb.music.enums.ResponseEnum.*;

/**
 * @author 最酷的桃儿wjc
 * * @date 2022/5/12
 */
@Service
public class SingerServiceImpl implements SingerService {

    @Autowired
    private SingerMapper singerMapper;

    /**
     * 新增歌手
     * @param singer
     * @return
     */
    @Override
    public ResponseVo insertSinger(Singer singer) {
        int resultCount = singerMapper.insertSinger(singer);
        if (resultCount == 0){
            return ResponseVo.error(ERROR_INSERT);
        }
        return ResponseVo.success(SUCCESS_INSERT);
    }

    /**
     * 更新歌手图片信息
     * @param singer
     * @return
     */
    @Override
    public ResponseVo updateSingerPic(Singer singer,String storeAvatorPath) {
        int resultCount = singerMapper.updateSinger(singer);
        if (resultCount == 0){
            return ResponseVo.error(ERROR_UPLOAD);
        }
        Map<String,String> avatorMap = new HashMap();
        avatorMap.put("pic",storeAvatorPath);
        return ResponseVo.successData(SUCCESS_UPLOAD,avatorMap);
    }

    /**
     * 更新歌手信息
     * @param singer
     * @return
     */
    @Override
    public ResponseVo updateSinger(Singer singer) {
        int countUpdate = singerMapper.updateSinger(singer);
        if (countUpdate == 0){
            return ResponseVo.error(ERROR_UPDATE);
        }
        return ResponseVo.success(SUCCESS_UPDATE);
    }

    /**
     * 根据id删除歌手信息
     * @param id
     * @return
     */
    @Override
    public ResponseVo deleteSinger(Integer id) {
        int countDelete = singerMapper.deleteSinger(id);
        if (countDelete == 0){
            return ResponseVo.error(ERROR_DELETE);
        }
        return ResponseVo.success(SUCCESS_DELETE);
    }

    /**
     * 获取歌手信息
     * @param id
     * @return
     */
    @Override
    public ResponseVo<Singer> getSingerById(Integer id) {
        Singer singer = singerMapper.getSingerById(id);
        return ResponseVo.getData(singer);
    }

    /**
     * 获取歌手列表
     * @return
     */
    @Override
    public List<Singer> getSingerList() {
        return singerMapper.getSingerList();
    }

    /**
     * 模糊查询获取歌手列表
     * @param name
     * @return
     */
    @Override
    public ResponseVo<List<Singer>> getSingersOfName(String name) {
        List<Singer> singerList = singerMapper.getSingersOfName(name);
        return ResponseVo.getData(singerList);
    }

    @Override
    public List<Singer> getSingerOfSex(Integer sex) {
        return null;
    }
}
